package com.gxa.modules.property.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.modules.property.dto.ActivityToAdd;
import com.gxa.modules.property.dto.ActivityToUpdate;
import com.gxa.modules.property.entity.Activity;
import com.gxa.modules.property.mapper.ActivityMapper;
import com.gxa.modules.property.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public void add(ActivityToAdd activityToAdd) {
        this.activityMapper.add(activityToAdd);
    }

    @Override
    public void delete(Integer id) {
        this.activityMapper.delete(id);
    }

    @Override
    public void update(ActivityToUpdate activityToUpdate) {
        this.activityMapper.update(activityToUpdate);
    }
    @Override
    public PageInfo<Activity> queryActivity(Map<String,Object> params) {
        String page1 = (String) params.get("page");
        String limit1 = (String) params.get("limit");
        Integer page = Integer.valueOf(page1);
        Integer limit = Integer.valueOf(limit1);

        //条件查询
        String title = (String) params.get("title");
        String communityId = (String) params.get("communityId");

        PageHelper.startPage(page,limit);
        List<Activity> activityToQueryList = activityMapper.queryActivity(title,communityId);
        PageInfo<Activity> pageInfo = new PageInfo<>(activityToQueryList);
        return pageInfo;
    }
}
